home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / dmsmgr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-06  |  1.3 KB  |  80 lines

  1. #include "dmsmgr.hpp"
  2. #include <io.h>
  3.  
  4. dmsmgr::dmsmgr(unsigned long the_size, unsigned long num_elements) // numelements defaults to 1
  5. {
  6.     installed = FALSE;
  7.     errcode = 0;
  8.     thesize = the_size;
  9.     numelements = num_elements;
  10.     return;
  11. }
  12.  
  13. dmsmgr::~dmsmgr()
  14. {
  15.     if (fp)
  16.         fclose (fp);
  17. }
  18.  
  19. void
  20. dmsmgr::alloc_dmb()
  21. {
  22.     fp = tmpfile();
  23.     if (fp)        {
  24.         installed = TRUE;
  25.         chsize (fileno (fp), thesize * numelements);
  26.     } else    {
  27.         installed = FALSE;
  28.         errcode = errno;
  29.     }
  30.     return;
  31. }
  32.  
  33. char* dmsmgr::dmserr()
  34. {
  35.     static char errstring[26];
  36.  
  37.     sprintf (errstring, "DMS Disk Error #%d.", errcode);
  38.     return errstring;
  39. }
  40.  
  41. Boolean dmsmgr::stow (char far* send, size_t listnum)
  42. {
  43. size_t done;
  44.  
  45.     if (!is_installed())
  46.         return FALSE;
  47.     done = fseek (fp, listnum * thesize, SEEK_SET);
  48.     if (done)    {
  49.         errcode = errno;
  50.         return FALSE;
  51.     }
  52.     done = fwrite (send, thesize, 1, fp);
  53.     if (done == thesize)
  54.         return TRUE;
  55.     else    {
  56.         errcode = errno;
  57.         return FALSE;
  58.     }
  59. }
  60.  
  61. Boolean dmsmgr::fetch (char far* receive, size_t listnum)
  62. {
  63. size_t done;
  64.  
  65.     if (!is_installed())
  66.         return FALSE;
  67.     done = fseek (fp, listnum * thesize, SEEK_SET);
  68.     if (done)    {
  69.         errcode = errno;
  70.         return FALSE;
  71.     }
  72.     done = fread (receive, thesize, 1, fp);
  73.     if (done == thesize)
  74.         return TRUE;
  75.     else    {
  76.         errcode = errno;
  77.         return FALSE;
  78.     }
  79. }
  80.